package com.example.demo.leetcode.top100;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _67寻找旋转排序数组中的最小值
 * @description
 * @date 2023/06/24 9:56
 * <p>
 * ******************************************************
 */
public class _67寻找旋转排序数组中的最小值 {
    public int findMin(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int num0 = nums[0];
        int first = 0;
        if (nums.length != 1) {
            while (left <= right) {
                int mid = right - (right - left) / 2;
                if (mid > 0) {
                    if (nums[mid] < nums[mid - 1]) {
                        first = mid;
                        break;
                    } else if (nums[mid] > num0) {
                        left = mid + 1;
                    } else {
                        right = mid - 1;
                    }
                }
            }
        }
        return nums[first];
    }
}
